package com.example.hao.mvp.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;


import com.example.hao.mvp.R;
import com.example.hao.mvp.mvp.presenter.MainPresenter;
import com.example.hao.mvp.mvp.view.IMainView;
import com.example.hao.mvp.pojo.User;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.disposables.Disposable;

public class MainActivity extends AppCompatActivity implements IMainView {

    private static  String TAG = "Hao";
    @BindView(R.id.et_userName)
    EditText etUserName;
    @BindView(R.id.et_psw)
    EditText etPsw;
    @BindView(R.id.btn_register)
    Button btnRegister;
    @BindView(R.id.tv_show)
    TextView tvShow;
    private Disposable disposable;
    private MainPresenter mainPresenter;
    private String userName;
    private String psw;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        mainPresenter = new MainPresenter(this);
    }



    @OnClick(R.id.btn_register)
    public void onViewClicked() {
        userName = etUserName.getText().toString();
        psw = etPsw.getText().toString();

        mainPresenter.login(userName,psw);
    }

    @Override
    public void updateUserInfo(User user) {
        Log.d(TAG, "updateUserInfo: "+user.toString());
       tvShow.setText(user.toString());
    }

    @Override
    public void showErrInfo(int status, String msg) {
        Log.e(TAG, "showErrInfo: "+msg );
        if (status == 0) {
            Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        } else if (status == 1) {
//            new AlertDialog.Builder()
        }

    }
}
